/******************************************************************************
 *   ObjectFS - Embedded Object File-System
 *
 *   Provides a full, simple no-nonsense file-system for simple embedded devices.
 *   Written by James Walmsley, james@fullfat-fs.co.uk
 *
 *   Copyright 2010 James Walmsley
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *
 *   Removing the above notice is illegal and will invalidate this license.
 *****************************************************************************/

/*
	ObjectFS - Simple Static File-system for FLASH memories.
*/

#ifndef _OFS_H_
#define _OFS_H_

#include "ofs_types.h"
#include "ofs_config.h"
#include "ofs_error.h"
#include "ofs_memory.h"


typedef OFS_ERROR	(*OFS_DEV_READ) 	(OFS_UINT32 ulAddress, OFS_UINT32 Size, void *pBuffer, void *pParam);
typedef OFS_ERROR	(*OFS_DEV_WRITE)	(OFS_UINT32 ulAddress, OFS_UINT32 Size, void *pBuffer, void *pParam);
typedef OFS_ERROR	(*OFS_DEV_ERASE) 	(void *pParam);	// Erases the entire flash.

typedef struct _OBJECT_MANAGER {
	OFS_DEV_WRITE	pfnWriteDevice;
	OFS_DEV_READ	pfnReadDevice;
	OFS_DEV_ERASE	pfnEraseDevice;
	OFS_UINT32		ulDataBeginAddress;
	OFS_UINT32		ulTotalDescriptors;	// When mounted, provides the number of descriptors.
	void			*pParam;
} OFS_MANAGER;

typedef struct {
	OFS_UINT16 usWidth;					// Width of image.
	OFS_UINT16 usHeight;				// Height of image.
} OFS_IMAGEPARAM;

typedef union {
	OFS_UINT32		u32;
	OFS_IMAGEPARAM	oImageInfo;
} OFS_TYPEDATA;

/*typedef enum {
	OFS_IMAGE = 0x0005,						///< RAW Image Data (16bpp). (Includes image dimensions etc).
	OFS_DATA,						///< Standard data.
	OFS_STRING,						///< String Data.
	OFS_CONFIG,						///< Configuration object.
	OFS_EMPTY,						///< An unused slot.
} OFS_TYPE;*/

#define OFS_TYPE_DATA	0x00000001
#define OFS_TYPE_IMAGE	0x00000002
#define OFS_TYPE_STRING	0x00000003
#define OFS_TYPE_CONFIG	0x00000004
#define OFS_TYPE_EMPTY	0xFFFFFFFF
#define OFS_TYPE_ERASED	0x00000000

typedef OFS_UINT32	OFS_TYPE;

typedef struct _OBJECT {
	OFS_UINT32		ulStartAddress;	// Where the object starts on the memory.
	OFS_UINT32 		ulSize;			// The objects (fixed) size.
	OFS_TYPE		eType;			// The objects type.
	OFS_TYPEDATA	oTypeData;		// Information relating to the object type.
	OFS_UINT32		FilePointer;	// File pointer.
	OFS_MANAGER		*pOMan;			// Pointer to the Object Manager.
} OFS_OBJECT;



OFS_ERROR OFS_InitObjectManager	(OFS_MANAGER *pOman, OFS_DEV_READ pfnRead, OFS_DEV_WRITE pfnWrite, OFS_DEV_ERASE pfnErase, void *pParam);
OFS_ERROR OFS_FormatFlash		(OFS_MANAGER *pOman, OFS_UINT32 nDescriptors, const OFS_INT8 *szpVolumeName);
OFS_ERROR OFS_MountFilesystem	(OFS_MANAGER *pOMan);
OFS_ERROR OFS_CreateObject		(OFS_MANAGER *pOMan, const OFS_INT8 *szpName, OFS_UINT32 Size, OFS_TYPE eObjectType, OFS_TYPEDATA *oTypeData);
OFS_ERROR OFS_ReadDevice		(OFS_MANAGER *pOman, OFS_UINT32 ulAddress, OFS_UINT32 Size, void *pBuffer);
OFS_ERROR OFS_WriteDevice		(OFS_MANAGER *pOman, OFS_UINT32 ulAddress, OFS_UINT32 Size, void *pBuffer);

#endif
